package com.example.onlineeducation.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.example.onlineeducation.base.BaseViewModel
import com.example.onlineeducation.data.entity.TopicEntity
import com.example.onlineeducation.repository.StudyRepository
import com.yc.jetpacklib.net.YcResult
import kotlinx.coroutines.flow.collectLatest

class TopicGroupVM : BaseViewModel() {
    private val mStudyRepository: StudyRepository by lazy { StudyRepository(mApiService) }


    private val _mTopicListDataModel = MutableLiveData<YcResult<List<TopicEntity>?>>()
    val mTopicListDataModel: LiveData<YcResult<List<TopicEntity>?>> = _mTopicListDataModel

    fun getTopicList(projectId: String, groupId: String) = ycLaunch {
        mStudyRepository.getTopicList(projectId, groupId).collectLatest {
            _mTopicListDataModel.postValue(it)
        }
    }
}
